package com.wtwd.wtwddevice.deviceserver.handler.processimpl;


import com.wtwd.device.annotation.MsgType;
import com.wtwd.device.constant.MsgTypeEnum;
import com.wtwd.device.mqtentity.MessageBase;
import com.wtwd.device.protocol.WTProtocol;
import com.wtwd.wtwddevice.deviceserver.handler.MsgHandlerFactory;
import com.wtwd.wtwddevice.deviceserver.handler.ProcessMessageHandler;
import com.wtwd.wtwddevice.deviceserver.netty.LocalSessions;
import io.netty.channel.Channel;

/**
 * 设备离线
 */
@MsgType(MsgTypeEnum.DEVICE_OFFLINE)
public class OfflineHandle implements ProcessMessageHandler {


    @Override
    public WTProtocol processMsg(WTProtocol wtProtocol, Channel channel) {
        String deviceKey = LocalSessions.removeByChannel(channel);
        if (deviceKey == null) return null;
        MsgHandlerFactory.getMqSendMessage()
                .push(
                        MessageBase.builder()
                                .deviceKey(deviceKey)
                                .wtProtocol(wtProtocol)
                                .build());
        return null;
    }

}
